<template>
  <star-table
    :ref="ref"
    :config="config"
    :loading="loading"
    :data="data"
    :columns="columns"
    :additionalAction="additionalAction"
    :pageSizeOpts="pageSizeOpts"
    :pageNavigation="pageNavigation"
    :queryFormItem="queryFormItem"
    :collapseFormItem="collapseFormItem"
    :btnShowFun="btnShowFun"
    :rowbgc="rowbgc"
    :tableStyle="{ overflow: 'hidden !important' }"
    @loadPage="loadPage"
    @handleEdit="handleEdit"
    @handleDelete="handleDelete"
    @handleDetail="handleDetail"
    @handleClick="handleClick"
    @handleDbClick="handleDbClick"
    @handleCreate="handleCreate"
    @handleDeleteMultiple="handleDeleteMultiple"
    @handleSearch="handleSearch"
    @handleReset="handleReset"
  ></star-table>
</template>

<script>
const ref = "waitApprovalTable";
export default {
  name: ref,
  components: {},
  inject: ["anc"],
  data() {
    return {
      ref,
      loading: false,
      pageNavigation: {
        total: 0,
        pageSize: 10,
        pageNumber: 1,
      },
      jobOptions: [],
    };
  },
  props: {
    data: {
      default: () => {
        return [];
      },
    },
  },
  watch: {},
  computed: {
    config() {
      return {
        search: true,
        addButton: false,
        batchDeleteButton: false,
        downloadIcon: false,
        uploadIcon: false,
        uploadUrl: "/",
        tableSizeIcon: false,
        fullscreenIcon: false,
        refreshIcon: false,
        columnSettingIcon: false,
        checkColumnDisabled: true,
        action: false, // 操作
        additionalAction: true, // 新增自定义
      };
    },
    columns() {
      return [
        {
          key: "planBatchNo",
          title: "计划批次号",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "productId",
          title: "产物规格",
          minWidth: 200,
          align: "center",
          show: true,

          render: (h, params) => {
            return h(
              "div",
              {},
              this._$getOptionValue(
                this.anc.productOptions,
                params.row.productId
              )
            );
          },
        },
        // {
        //   key: "planType",
        //   title: "计划类型",
        //   minWidth: 200,
        //   align: "center",
        //   show: true,
        //   config: { type: "text" },
        // },
        {
          key: "status",
          title: "状态",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "approveStatus",
          title: "审批状态",
          minWidth: 100,
          align: "center",
          show: true,
        },
        {
          key: "planStartTime",
          title: "计划开始时间",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "planEndTime",
          title: "计划结束时间",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "startTime",
          title: "开始时间",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "endTime",
          title: "结束时间",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "totalCapacity",
          title: "计划产量",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "usedCapacity",
          title: "已产量",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "restCapacity",
          title: "剩余未产",
          minWidth: 200,
          align: "center",
          show: true,
        },
        {
          key: "remark",
          title: "备注",
          minWidth: 200,
          align: "center",
          show: true,
        },
      ];
    },
    additionalAction() {
      return {
        key: "additionalAction",
        title: "附加操作",
        slot: "additionalAction",
        width: 200,
        fixed: "right",
        align: "center",
        show: true,
        buttons: [
          {
            title: "退回",
            // style: (row, column, index, item, i) => {
            //   console.log({ row, column, index, item, i });
            //   if (row.status != "创建") {
            //     return {
            //       "pointer-events": "none",
            //       color: "gray",
            //     };
            //   }
            // },
            event: (row, index) => this.anc.handleApprovalModal(row,"退回"),
          },
          {
            title: "批准",
            // style: (row, column, index, item, i) => {
            //   console.log({ row, column, index, item, i });
            //   if (row.status != "创建") {
            //     return {
            //       "pointer-events": "none",
            //       color: "gray",
            //     };
            //   }
            // },
            event: (row, index) => this.anc.handleApprovalModal(row,"批准"),
          },
        ],
      };
    },
    pageSizeOpts() {
      return [10, 30, 50, 100];
    },

    queryFormItem() {
      return [];
    },
    collapseFormItem() {
      return [];
    },
    btnShowFun() {
      return function () {
        return true;
      };
    },
    rowbgc() {
      return "red";
    },
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.$set(this.anc.vms, this.ref, this);

      this.loadPage(this.pageNavigation, {});
    });
  },
  methods: {
    loadPage(pageNavigation, filter) {
      //   //删除查询项中属性值为空的查询条件
      this.anc.waitApprovalLoadPage(pageNavigation, filter);
    },
    handleEdit(row, index) {
      console.log(row, index);
      this.anc.handleEdit(row, index);
    },
    handleDelete(row, index) {
      this.anc.handleDelete(row, index);
    },
    handleDetail(row, index) {
      this.anc.handleDetail(row);
    },
    handleClick(row, index) {},
    handleDbClick(row, index) {},
    handleDeleteMultiple(selection) {},
    handleSearch(filter) {
      this.pageNavigation.pageNumber = 1;
      this.loadPage(this.pageNavigation, filter);
    },
    handleCreate() {},
    handleReset() {
      this.pageNavigation.pageNumber = 1;
      this.loadPage(this.pageNavigation, {});
    },
  },
};
</script>
<style scoped></style>
